import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { MountEquipBaseItem } from "../mountEquip/MountEquipBaseItem";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { ItemMenuRegister } from "../../common/menu/ItemMenuRegister";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ItemData } from "../../../resource/info/ItemData";
//class MountEquiptItemSp
    
    export  class MountEquiptItemSp /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initView();
            return;
        }

        /* internal  */initView(): void
        {
            var loc1=null;
            this._itemArr = [];
            var loc2=0;
            while (loc2 < 4) 
            {
                ObjCreate.createBg(loc2 * 57, 3, 38, 38, this, ImagesConst.PackItemBg);
                loc1 = new MountEquipBaseItem();
                loc1.x = 2 + loc2 * 57;
                loc1.y = 6;
                loc1.setSize(32, 32);
                loc1.isShowLock = true;
                loc1.doubleClickEnabled = true;
                loc1.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.fastOperate);
                addChild(loc1);
                this._itemArr.push(loc1);
                ++loc2;
            }
            LoaderHelp.addResCallBack(ResFileConst.mount, this.onLoadBmResource);
            return;
        }

        /* internal  */fastOperate(arg1: Object /* flash.events.MouseEvent */): void
        {
            ItemMenuRegister.hideOpList();
            var loc1=arg1.target as MountEquipBaseItem;
            if (loc1 && loc1.itemData) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.MountEuqipUndress, loc1.itemData));
            }
            return;
        }

        /* internal  */onLoadBmResource(): void
        {
            return;
        }

        public updateEquipt(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < arg1.length) 
            {
                loc1 = arg1[loc2];
                if (loc1 && !(loc1 == ItemData.nullItemData)) 
                {
                    (this._itemArr[loc2] as MountEquipBaseItem).itemData = loc1;
                    (this._itemArr[loc2] as MountEquipBaseItem).setEquipType(0);
                }
                else 
                {
                    (this._itemArr[loc2] as MountEquipBaseItem).itemData = null;
                    (this._itemArr[loc2] as MountEquipBaseItem).setEquipType(loc2 + 1);
                }
                ++loc2;
            }
            return;
        }

        /* internal */ /* var */_itemArr: Array<any>;
    }
